package com.meij.fragment;

import android.os.Bundle;

import com.fragment.BaseFragment;
import com.meij.R;
import com.meij.activity.MjActivity;
import com.meij.bean.Album;
import com.meij.http.Url;

public class PicFragment extends BaseFragment {
	private Album album;

	public static PicFragment newInstance(Album album) {
		PicFragment fragment = new PicFragment();
		Bundle args = new Bundle();
		args.putSerializable("album", album);
		fragment.setArguments(args);
		return fragment;
	}

	public PicFragment() {
	}

	@Override
	protected int getID() {
		return R.layout.fragment_pic;
	}

	@Override
	protected void editView() {
		album = (Album) getArguments().getSerializable("album");
		aq.id(R.id.iv_pic).image(Url.ctx + album.getImg());
	}

	@Override
	public void setUserVisibleHint(boolean isVisibleToUser) {
		super.setUserVisibleHint(isVisibleToUser);
		if (isVisibleToUser) {
			if (album == null) {
				album = (Album) getArguments().getSerializable("album");
			}
			getData();
		}
	}

	private void getData() {
		MjActivity activity = (MjActivity) getActivity();
		String url = Url.photo_detail + "?photoId=" + album.getId();
		activity.getJson(url);
	}
}